#!/bin/bash
# This script runs the git source unit tests

###SHELLPACK preamble gitsource-bench v2.15.1

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam	--iterations GITSOURCE_ITERATIONS
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK init_only_start
###SHELLPACK check_install_required_continue gitsource-${VERSION}
cp -ar $SHELLPACK_SOURCES/gitsource-${VERSION}-installed $SHELLPACK_DATA || die "Failed to copy gitsource-$VERSION-installed"
###SHELLPACK init_only_end

cd $SHELLPACK_DATA/gitsource-${VERSION}-installed || die Failed to cd to gitsource-$VERSION-installed

echo Warming run
make test > $LOGDIR_RESULTS/warmup.log 2>&1
tail $LOGDIR_RESULTS/warmup.log

monitor_pre_hook $LOGDIR_RESULTS $P
###SHELLPACK iteration_begin $GITSOURCE_ITERATIONS
	echo Starting iteration $ITERATION/$GITSOURCE_ITERATIONS
	$TIME_CMD -o $LOGDIR_RESULTS/gitsource-${ITERATION}.time \
		make test \
		> $LOGDIR_RESULTS/gitsource-${ITERATION}.log 2>&1
	tail $LOGDIR_RESULTS/gitsource-${ITERATION}.log
	gzip $LOGDIR_RESULTS/gitsource-${ITERATION}.log
	cat $LOGDIR_RESULTS/gitsource-${ITERATION}.time
###SHELLPACK iteration_end
monitor_post_hook $LOGDIR_RESULTS $P

cat $LOGDIR_RESULTS/gitsource-*.time | grep elapsed | tee $LOGDIR_RESULTS/time
rm -rf $SHELLPACK_DATA/gitsource-${VERSION}-installed

exit $SHELLPACK_SUCCESS
